--fn GetCoreInstance Objs Cores InstancesByCores Instances = 
fn GetCoreInstance Objs Cores InstancesByCores Instances = 
(
	for i=1 to Objs.count do
	(
		local Obj=Objs[i]
		local core=undefined
		for j=1 to  Cores.count do
		(
			if (areNodesInstances Obj Cores[j]) then
			(
				core=Cores[j]
				break
			)
		)
		if core==undefined then
		(
			append Cores Obj
			append InstancesByCores Obj
			append Instances Obj
		)
		else
		(
			append InstancesByCores Core
			append Instances Obj
		)
	)
)




fn GetYaw transform =
(
	return (transform as eulerangles).z
)
fn GetPitch transform =
(
	return (transform as eulerangles).x
)
fn GetRoll transform =
(
	return (transform as eulerangles).y
)

fn RHTranslationToLH translation =
(
return point3 translation.x translation.z translation.y
)







function RenderableObjectManager PathFile Cores InstBycore Instances=
(
	-- TODO path con data/level/etc?
	FileName = Pathfile + "Data\\Renderable_Objects.xml"
	local file = createfile FileName
	format "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" to:file
	format "<renderable_objects>\n" to:file

	for i=1 to Instances.count do
	(
		try
		(
			if (getUserProp Instances[i] "Export") then
			(
				format "\t<mesh_instance  Layer=\"%\"  Name=\"%\"  Core=\"%\"  Pos=\"% % %\"  Yaw=\"%\"  Pitch=\"%\"  Roll=\"%\" Scale= \"%\">\n" (getUserProp Instances[i] "Layer") Instances[i].name InstByCore[i].name Instances[i].position.x Instances[i].position.y Instances[i].position.z (GetYaw Instances[i].transform) (GetPitch Instances[i].transform) (GetRoll Instances[i].transform) (RHTranslationToLH Instances[i].transform.scale) to:file
			)
			
		)
		catch
		(
			format ("el objeto "+(Instances[i].name as string )+" no tiene export property")
		)
		
		
	)--fin for

	format "</renderable_objects>" to:file
	fflush file
	close file
)


Cores=#()
InstancesByCores=#()
Instances=#()
GetCoreInstance $* Cores InstancesByCores Instances
getUserProp Instances[1] "Export"
RenderableObjectManager "C:\\Users\\Sandra\\Documents\\MASTER CREACION VDJ\\" Cores InstancesByCores Instances

